//获取openid
/*
opt.state          公众号id
opt.debug          是否测试模式
opt.domain         公众号授权域名
opt.auth           是否强制授权
*/

var state

function getUserInfo() {
    $.ajax({
        type: 'Post',
        url: '/2018-4/2020/rc0618/WebServices/Ajax.aspx',
        data: {
            "Cmd": "inquireabout",
            "openid": WxUserInfo.openid,
        },
        dataType: "json",
        async: false,
        cache: false,
        beforeSend: function() {},
        success: function(result) {
            if (result.state == 1) {
                console.log('未参与问卷调查')
            } else if (result.state == 3) {
                console.log('已参与问卷调查')
                $('#loadDiv').attr('state', 3);
                $('#loadDiv').fadeOut();
                $('.from4').fadeIn();
                $(".name").val(result.rows[0].name)
                $(".tel").val(result.rows[0].phone)
                $(".day").val(result.rows[0].receiveTime)
                $(".adviser").val(result.rows[0].seller)
                $("input").attr('disabled', 'disabled')
                $(".submit_btn").css("display", "none")

            } else {
                alert(result.message)
            }
        },
        fail: function(err) {
            alert('网络错误')
        }
    })

}

//问卷提交
function submit() {
    var name = $(".name").val();
    var phone = $(".tel").val();
    var receiveTime = $(".day").val();
    var seller = $(".adviser").val()
    var participate = $(".submit_btn").attr("participate")
    if (name == "") {
        alert('请输入您的姓名');
        return false;
    } else {
        var zhengze = eval('/^[\\u4e00-\\u9fa5]{2,8}$/');
        var yanzheng = zhengze.exec(name);
        if (!yanzheng) {
            alert('姓名输入有误，格式为2—8位中文汉字');
            return false;
        }
    }
    if (phone == "") {
        alert('请输入您的手机号码');
        return false;
    } else {
        var zhengze = eval('/^1([3,4,5,6,7,8,9]{1}[0-9]{9})$/i');
        var yanzheng = zhengze.exec(phone);
        if (!yanzheng) {
            alert('手机号码输入有误，请重新输入');
            return false;
        }
    }
    if (receiveTime == "") {
        alert('请输入领取日期');
        return false;
    } else {
        receiveTime = parseInt(receiveTime)
        if (receiveTime == 22 || receiveTime == 23 || receiveTime == 24) {

        } else {
            alert('日期输入有误，请输入22-24任意数字');
            return false;
        }
    }
    if (seller == "") {
        alert('请输入您的专属置业顾问');
        return false;
    } else {
        var zhengze = eval('/^[\\u4e00-\\u9fa5]{2,8}$/');
        var yanzheng = zhengze.exec(seller);
        if (!yanzheng) {
            alert('置业顾问输入有误，格式为2—8位中文汉字');
            return false;
        }
    }
    $.ajax({
        type: "Post",
        url: "/2018-4/2020/rc0618/WebServices/Ajax.aspx",
        data: {
            "Cmd": "tijiao",
            "openid": WxUserInfo.openid,
            "nickname": WxUserInfo.nickname,
            "headimg": WxUserInfo.headimgurl,
            "q1": q1,
            "q2": q2,
            "q3": q3,
            "q4": q4,
            "q5": q5,
            "q6": q6,
            "name": name,
            "phone": phone,
            "receiveTime": receiveTime,
            "seller": seller,
            "participate": participate,
        },
        dataType: "json",
        async: false,
        cache: false,
        beforeSend: function() {},
        success: function(result) {
            if (result.state == 1) {
                $('.from4').fadeOut();
                $('.from5').fadeIn();
            } else if (result.state == 2) {
                alert('提交失败请刷新');
            } else if (result.state == 3) {
                console.log('您已参与问卷调查');
            } else if (result.state == 4) {
                alert(result.message);
            } else if (result.state == 5) {
                alert(result.message);
            }
        },
        fail() {
            alert("网络异常")
        }
    });
}

//微信分享
/*
opt.state           公众号
opt.debug           是否debug模式
opt.config_debug    wx.config是否开启debug
opt.domain          ajax程序所在域名，默认不需要更改
opt.img             分享图片
opt.url             分享地址
opt.title           分享标题
opt.desc            分享描述
*/
function changeShare(n) {
    wx_share.config({
        state: shareOpenID //分享的公众号id
            ,
        debug: false //测试弹窗信息，默认true
            //, config_debug: false               //微软官方的js-sdk配置是否开启，分享失败的时候可以尝试开启调试
            //, domain: 'weixin.juzhen.com'      //分享程序所在的域名，默认不修改
            ,
        img: 'http://rongchuang.juzhen01.com/2018-4/2020/jxt0618/images/share.jpg',
        url: 'http://rongchuang.juzhen01.com/2018-4/2020/jxt0618/index.html',
        title: "融创玖玺台 | 极尽温柔，触新生活",
        desc: "复录你每一次选择"
    });
};